﻿<UserControl x:Class="XSemmel.TreeView.EditorTree"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:fluent="clr-namespace:Fluent;assembly=Fluent"
             xmlns:TreeView="clr-namespace:XSemmel.TreeView" 
             xmlns:Commands="clr-namespace:XSemmel.TreeView.Commands" mc:Ignorable="d" 
             d:DesignHeight="50" d:DesignWidth="300">
    <UserControl.Resources>
        <Commands:CopyXPathCommand x:Key="CopyXPathCommand"/>
        <Commands:CommentOutCommand x:Key="CommentOutCommand"/>
        <Commands:RenameCommand x:Key="RenameCommand"/>
        <Commands:SelectCodeCommand x:Key="SelectCodeCommand"/>
        <Commands:ShowSchemaInfoCommand x:Key="ShowSchemaInfoCommand"/>
        <Commands:DeleteCommand x:Key="DeleteCommand"/>
    </UserControl.Resources>
    <DockPanel>
        <DockPanel DockPanel.Dock="Top">
            <Button DockPanel.Dock="Right"
                    Width="25"
                    Click="btnRemoveFilter_Click"
                    TabIndex="2"
                    Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
                    ToolTip="Remove filter">
                <Image Source="/Images/FilterClear_16x16.png" Height="16" Width="16" />
            </Button>
            <Button DockPanel.Dock="Right"
                    Width="25"
                    TabIndex="1"
                    Click="btnApplyFilter_Click"
                    Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
                    ToolTip="Apply filter">
                <Image Source="/Images/Filter_16x16.png" Height="16" Width="16" />
            </Button>
            
            <TextBox x:Name="_edtFilter" x:FieldModifier="private" 
                     TabIndex="0"
                     KeyDown="edtFilter_KeyDown" 
                     ToolTip="Show only nodes containing this text"/>
        </DockPanel>

        <TreeView:XmlTree x:Name="tree" Tag="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type fluent:RibbonWindow}}, Path=Data}" >
            <TreeView:XmlTree.ContextMenu>
                <ContextMenu>
                    <!-- http://stackoverflow.com/questions/504533/commandparameters-in-contextmenu-in-wpf -->
                    <MenuItem
                        Header="Copy XPath"
                        Command="{StaticResource CopyXPathCommand}"
                        CommandParameter="{Binding PlacementTarget.Tag, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"
                    >
                        <MenuItem.Icon>
                            <Image>
                                <Image.Source>
                                    <BitmapImage UriSource="/Images/112_ArrowCurve_Blue_Right_16x16_72.png" />
                                </Image.Source>
                            </Image>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem
                        Header="Select in editor"
                        Command="{StaticResource SelectCodeCommand}"
                        CommandParameter="{Binding PlacementTarget.Tag, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"
                    >
                        <MenuItem.Icon>
                            <Image>
                                <Image.Source>
                                    <BitmapImage UriSource="/Images/View_16x16.png" />
                                </Image.Source>
                            </Image>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem
                        Header="Show schema info"
                        Command="{StaticResource ShowSchemaInfoCommand}"
                        CommandParameter="{Binding PlacementTarget.Tag, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"
                    >
                      <MenuItem.Icon>
                        <Image>
                          <Image.Source>
                            <BitmapImage UriSource="/Images/BookVshelp_16x16.png" />
                          </Image.Source>
                        </Image>
                      </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem
                        Header="Comment out"
                        Command="{StaticResource CommentOutCommand}"
                        CommandParameter="{Binding PlacementTarget.Tag, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"
                    >
                        <MenuItem.Icon>
                            <Image>
                                <Image.Source>
                                    <BitmapImage UriSource="/Images/Comment_16x16.png" />
                                </Image.Source>
                            </Image>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem
                        Header="Rename"
                        Command="{StaticResource RenameCommand}"
                        CommandParameter="{Binding PlacementTarget.Tag, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"
                    >
                        <MenuItem.Icon>
                            <Image>
                                <Image.Source>
                                    <BitmapImage UriSource="/Images/RenameFolderHS.png" />
                                </Image.Source>
                            </Image>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem
                        Header="Delete"
                        Command="{StaticResource DeleteCommand}"
                        CommandParameter="{Binding PlacementTarget.Tag, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"
                    >
                        <MenuItem.Icon>
                            <Image>
                                <Image.Source>
                                    <BitmapImage UriSource="/Images/Delete_16x16.png" />
                                </Image.Source>
                            </Image>
                        </MenuItem.Icon>
                    </MenuItem>
                    
                </ContextMenu>
            </TreeView:XmlTree.ContextMenu>
        </TreeView:XmlTree>

    </DockPanel>
</UserControl>
